<?php
require '../model/Db.php';
$Db = Db::getInstance();
if(isset($_POST['submit'])){
	$_POST = $Db->escape($_POST);
	if($_POST['token'] == REG_TOKEN){
		$isExist = $Db->find([
			table => ['bbs_manager'],
			where => "user = '{$_POST['user']}'"
		]);
		if(!$isExist){
			$flag = $Db->save([
				table => 'bbs_manager',
				map => [
					user => $_POST['user'],
					pwd => sha1(md5($_POST['pwd'])),
					phone =>  $_POST['phone']
				]
			]);
			$msg = $flag?'注册成功啦~':'网络崩溃了,555~';
			$class = $flag?'ok':'err';
			$reurl = $flag?'login.php':'';
		}else{
			$msg = '注册失败了,管理员账号已被注册~';
			$class = 'err';
			$reurl = '';
		}
	}else{
		$msg = '注册失败了,注册码错误~';
		$class = 'err';
		$reurl = '';
	}
	include './view/skip.html';
}else{
	$css = ['../public/css/admin-reg.css'];
	include './view/reg.html';
}
